package com.ruoyi.web.controller.myplan.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AwPlanDetail;
import com.ruoyi.system.service.IAwPlanDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 详细计划Controller
 *
 * @author anxinr
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/system/detail")
public class AwPlanDetailController extends BaseController
{
    @Autowired
    private IAwPlanDetailService awPlanDetailService;

    /**
     * 查询详细计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwPlanDetail awPlanDetail)
    {
        startPage();
        List<AwPlanDetail> list = awPlanDetailService.selectAwPlanDetailList(awPlanDetail);
        return getDataTable(list);
    }

    /**
     * 导出详细计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "详细计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AwPlanDetail awPlanDetail)
    {
        List<AwPlanDetail> list = awPlanDetailService.selectAwPlanDetailList(awPlanDetail);
        ExcelUtil<AwPlanDetail> util = new ExcelUtil<AwPlanDetail>(AwPlanDetail.class);
        util.exportExcel(response, list, "详细计划数据");
    }

    /**
     * 获取详细计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(awPlanDetailService.selectAwPlanDetailById(id));
    }

    /**
     * 新增详细计划
     */
    @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "详细计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwPlanDetail awPlanDetail)
    {
        return toAjax(awPlanDetailService.insertAwPlanDetail(awPlanDetail));
    }

    /**
     * 修改详细计划
     */
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "详细计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwPlanDetail awPlanDetail)
    {
        return toAjax(awPlanDetailService.updateAwPlanDetail(awPlanDetail));
    }

    /**
     * 删除详细计划
     */
    @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "详细计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(awPlanDetailService.deleteAwPlanDetailByIds(ids));
    }

    @GetMapping("/complete")
    public AjaxResult complete(@RequestParam("id") Long id) {
        return success(awPlanDetailService.completePlanDetail(id)) ;
    }
}
